package com.pmsystem.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.KeyRecord;
import com.pmsystem.service.KeyRecordService;
import com.pmsystem.util.BeanUtil;

@Controller
@RequestMapping(value="admin")
public class KeyRecordController {

	@Autowired
	private KeyRecordService keyRecordService;
	
	/**
	 * 
	 * <p>Title: addKeyRecord</p >  
	 * <p>Description: 添加借钥匙记录</p >  
	 * @author 泽强
	 * @param keyRecord
	 * @return
	 */
	@RequestMapping(value="addKeyRecord",method=RequestMethod.POST)
	@ResponseBody
	public Object addKeyRecord(@RequestParam Map<String,Object> map) {
		KeyRecord keyRecord= BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map), KeyRecord.class);
		boolean flag = keyRecordService.addKeyRecord(keyRecord);
		if(flag) {
			return "success";
		}
		return "error";
	}
	
	/**
	 * 
	 * <p>Title: updateKeyRecord</p >  
	 * <p>Description: 修改借钥匙记录</p >  
	 * @author 泽强
	 * @param keyRecord
	 * @return
	 */
	@RequestMapping(value="updateKeyRecord",method=RequestMethod.POST)
	@ResponseBody
	public Object updateKeyRecord(@RequestParam Map<String,Object> map) {
		KeyRecord keyRecord= BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map), KeyRecord.class);
		boolean flag = keyRecordService.updateKeyRecord(keyRecord);
		if(flag) {
			return "success";
		}
		return "error";
	}
	
	/**
	 * 
	 * <p>Title: findKeyRecord</p >  
	 * <p>Description: 按一定条件查询借钥匙记录</p >  
	 * @author 泽强
	 * @param map
	 * @return
	 */
	@RequestMapping(value="findKeyRecord",method=RequestMethod.GET)
	@ResponseBody
	public Object findKeyRecord(@RequestParam Map<String,Object> map) {
		List<KeyRecord> list =keyRecordService.findKeyRecord(map);		
		return list;
	}
}
